<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-model="ftModel">
        <select v-model="sltModel">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
        </select>
        <input type="text" v-model="mdModel">
        <input type="button" value="=" @click="btnClick">
        <input type="text" v-model="ltModel">
    </div>
</body>

</html>
<script src="js/vue3.4.21.js"></script>
<script>
    const {
        createApp,
        ref
    } = Vue
    createApp({
        setup() {
            const ftModel = ref("")
            const mdModel = ref("")
            const ltModel = ref("")
            const sltModel = ref("")

            function btnClick() {
                if (sltModel.value == "+") {
                    ltModel.value = Number(ftModel.value) + Number(mdModel.value)
                        //eval() 解析字符串中的运算符:ltModel.value = eval(ftModel.value) + eval(mdModel.value)
                } else if (sltModel.value == "-") {
                    ltModel.value = ftModel.value - mdModel.value
                } else if (sltModel.value == "*") {
                    ltModel.value = ftModel.value * mdModel.value
                } else if (sltModel.value == "/") {
                    if (mdModel.value <= "0") {
                        alert("除数为零")
                    } else {
                        ltModel.value = ftModel.value / mdModel.value
                    }

                }
            }

            return {
                ftModel,
                mdModel,
                ltModel,
                sltModel,
                btnClick
            }
        }
    }).mount("#app")
</script>